#include "../include/interrupt.h"
#include "timer-IT.h"
extern void printf(const char *fmt, ...);
unsigned int i = 0;
// 中断处理函数，没有形参，没有返回值，中断处理函数中不允许出现延时函数
void do_irq(void) 
{
	// 1. 获取中断号   GICC_IAR[9:0]
	unsigned int irq_num;
	irq_num = GICC->IAR & 0x3FF;
	// 2. 进入到中断处理程序
	switch(irq_num) {
        case 55:
            printf("fire interrupt ID = %d\n", irq_num);
            hal_exti_IT_clear(EXTI5_INPUT_EVENT,RISING);
            hal_gic_IT_clear(EXTI5_ID);
            break;
		case 82:
            printf("tim5 1s interrupt ID = %d\n", irq_num);
            TIM5->SR &= (~(0x1 << 0));
            hal_gic_IT_clear(TIM5_ID);
            break;
		case 97:
			break;
		case 98:
			break;
		case 99:  // 99号中断处理程序
			// 3. 调用99号中断处理程序   让LED1交替闪烁/或者使用printf打印函数
            GPIOE->ODR ^= (0x1 << 10);
            printf("KEY1 interrupt ID = %d\n", irq_num);
			// 4. 清除EXTI层中断挂起标志位   EXTI_FPR1[9] = 0x1
            hal_exti_IT_clear(EXTI9_INPUT_EVENT,FALLING);
			// 5. 清除GICD层中断挂起标志位   GICD_ICPENDR3[3] = 0x1 
            hal_gic_IT_clear(EXTI9_ID);
			break;
		case 100:
			break;
	}
	// 6. 清除GICC层的中断号  GICC_EOIR
	GICC->EOIR = irq_num;

}
